#
# @lc app=leetcode.cn id=203 lang=python3
#
# [203] 移除链表元素
#
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

# @lc code=start
# Definition for singly-linked list.

class Solution:
    def removeElements(self, head: ListNode, val: int) -> ListNode:
        
        newHead = ListNode()
        temp = head
        newHead.next = head
        preNode = newHead
        while temp is not None:
            if temp.val == val:
                preNode.next = temp.next
                temp = temp.next
            else:
                preNode = preNode.next
                temp = temp.next
        return newHead.next
# @lc code=end

